package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import service.UserService;

import javax.servlet.http.HttpSession;

@Controller
public class HomeController {

    @Autowired
    UserService userService;

    @RequestMapping("/*")
    public ModelAndView begin(Model model) {
        return new ModelAndView("redirect:/home/");
    }

    @RequestMapping("/home/")
    public ModelAndView home(RedirectAttributes redirectAttrs, HttpSession httpSession) {
        ModelAndView modelAndView = new ModelAndView("home");

        return modelAndView;
    }

    @RequestMapping("/moder/")
    public ModelAndView moder(RedirectAttributes redirectAttrs, HttpSession httpSession) {
        ModelAndView modelAndView = new ModelAndView("moder");

        modelAndView.addObject("userList", userService.getAll());

        return modelAndView;
    }

}
